package com.analysis.web;

import java.sql.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.analysis.common.ConfigUtil;
import com.analysis.model.KLine;
import com.analysis.model.Similarity;
import com.analysis.service.DataSetService;
import com.analysis.service.KLineService;
import com.analysis.service.OLSService;

@RestController
@RequestMapping("kline")
public class KLineController {
	private String similarityExe = ConfigUtil.getString("similarityExe");
	@Autowired
	private KLineService klineService;
    @Autowired
    private DataSetService dataSet;
	
    @Autowired
    private OLSService ols;
	@GetMapping("searchData")
	public List<String> searchData(){
        return dataSet.getSearchData();
	}
	
	@GetMapping("data")
	public List<KLine> getKline(@RequestParam(required=true, defaultValue="sh600000")String symbol){
		return klineService.getKline(symbol);
	}

    @GetMapping("analyze")
    public List<Similarity> analyze(String setName, String symbol, Date startDate, Date endDate) {
    	if("true".equalsIgnoreCase(similarityExe)){
    		return klineService.analyze(setName, symbol, startDate, endDate);
    	}else{
    		return klineService.analyzeWithoutExe(setName, symbol, startDate, endDate);
    	}
       
    }

    @GetMapping("olsAnalyze")
    public List<Similarity> olsAnalyze(String setName, String symbol, Date startDate, Date endDate) {
        return ols.olsAnalyse(setName, symbol, startDate, endDate,10);
    }

    @GetMapping("DTWAnalyze")
    public List<Similarity> DTWAnalyze(String setName, String symbol, Date startDate, Date endDate) {
    	if("true".equalsIgnoreCase(similarityExe)){
    		return klineService.DTWAnalyze(setName, symbol, startDate, endDate);
    	}else{
    		return klineService.DTWAnalyzeWithoutExe(setName, symbol, startDate, endDate);
    	}
       
    }

    @GetMapping("line")
    public List<String> line(String symbol, Date startDate, Date endDate){
        return klineService.getLine(symbol, startDate, endDate);
    }
}
